package com.lfnyxy.service.imp;

import com.lfnyxy.dao.ProductTypeDao;
import com.lfnyxy.dto.DropVo;
import com.lfnyxy.entity.ProductTypeEntity;
import com.lfnyxy.query.ProductTypeQuery;
import com.lfnyxy.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductTypeServiceImp implements ProductTypeService {
    @Autowired
    public ProductTypeDao productTypeDao;

    public int CreateItem(ProductTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return productTypeDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(ProductTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return productTypeDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <ProductTypeEntity> QueryPageList(ProductTypeQuery query) {
        int count = productTypeDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return productTypeDao.QueryPageList(query);
        }
        return null;
    }

    public List <ProductTypeEntity> QueryAll() {
        return productTypeDao.QueryAll();
    }

    public ProductTypeEntity QueryItem(int Id) {
        if (Id > 0) {
            return productTypeDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return productTypeDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    @Override
    public List <DropVo> QueryDrop() {
        return productTypeDao.QueryDrop();
    }

    private boolean CheckIsExist(ProductTypeEntity entity) {
        if (entity != null) {
            return productTypeDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}